#pragma once
class OutcomePhase: public GamePhase
{
private:
	Game * g;	//A pointer to the game object
	int currentPlayer;		//An indicator of which player is currently selecting their actions.
	bool done;
public:
	OutcomePhase(Game * a_game)
	{
		g = a_game;
		currentPlayer = 0;
		done = false;
	}

	void update(int a_ms)
	{
		if (!done)
		{
			for (int i = 0; i < MAX_PLAYERS; ++i)
			{
				g->getPlayer(i)->takePartInSplit = true;
			}
			for (int i = 0; i < MAX_PLAYERS; ++i)	//Loop through the players
			{
				if (g->getPlayer(i)->getSelectedAction() == TOOK_SHAME)
				{
					g->getPlayer(i)->takePartInSplit = false;
				}
				//Do damage, set Flags in player to see if they can take part in the split.
				//BANGBANGBANG get priority
				if (g->getPlayer(i)->getTarget() != NULL && g->getPlayer(i)->getSelectedAction() == BANGBANGBANG)	//If their target hasn't taken shame, and they used the priority attack.
				{
					//Wound their target.
					g->getPlayer(i)->getTarget()->takeDamage();
				}


			}

			for (int i = 0; i < MAX_PLAYERS; ++i)
			{
				//BANG is next.  Players wounded in BANGBANGBANG don't shoot though...
				if (g->getPlayer(i)->getTarget() != NULL && g->getPlayer(i)->getSelectedAction() == BANG)	//If this player has a target and if they are using a bang attack.
				{
					//Wound their target
					g->getPlayer(i)->getTarget()->takeDamage();
				}
			}
			done = true;
		}
		//Wait for input to go to the next phase
		switch (returnInput())
		{
		case ' ':
			undraw();
			g->setState(SPLIT_THE_POT);
			done = false;
			break;
		default: break;
		}

	}
	void draw()
	{
		for (int i = 0; i < MAX_PLAYERS; ++i)
		{
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),  FOREGROUND_INTENSITY| i+1);
			g->getPlayer(i)->draw(i);
			switch(g->getPlayer(i)->getSelectedAction())
			{
			case BANGBANGBANG:
				printf("BANG BANG BANG!");
				break;
			case BANG:
				printf("BANG!");
				break;
			case CLICK:
				printf("CLICK!");
				break;
			default:
				break;
			}
			printf("\n");
		}
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), WHITE);
	}

	void undraw()
	{
		gotoxy(0,0);
		for (int y = 0; y < 80; ++y)
			for (int x = 0; x < 80; ++x)
				putchar(' ');
	}
};